package com.onpositive.wiki3.catmodels;

import com.onpositive.wiki3.db.ITitleMapper;
import com.onpositive.wiki3.db.catmodel.Category;

public class PureLocationModel implements ICategoryModel{

	@Override
	public int score(Category cat) {
		String ss = cat.toString();
		if (ss.indexOf(',')==-1){
			return 0;
		}
		String[] split = ss.split("_");
		if (split.length!=2){
			return 0;
		}
		for (String s: split){
			if (s.endsWith(",")){
				String string = s=s.substring(0,s.length()-1);
				s=string;
			}
			if (!Character.isLetter(s.charAt(0))){
				return 0;
			}
			ITitleMapper titleMapper = cat.getStore().getDb().getTitleMapper();
			int id = titleMapper.getId(s);
			if (id==-1){
				id=titleMapper.getId(Character.toUpperCase(s.charAt(0))+s.substring(1));
				if (id!=-1){
					return 0;	
				}				
			}
			
		}		
		cat.setTag(ICategoryModel.LOOKS_LIKE_LOCATION);
		return 0;
	}

	@Override
	public String name() {
		return "location";
	}

	@Override
	public boolean isPossibleCategorization(Category cat) {
		return false;
	}

	@Override
	public String getPrimaryParentForm(Category cat) {
		return null;
	}

}
